import {
  getLocationToken,
  removeLocationToken,
  setLocationToken,
} from "@/utils/auth"
import { defineStore } from "pinia"
import { ref } from "vue"

export const useUserStore = defineStore("hm-user", () => {
  const token = ref(getLocationToken() || "")
  //存储Token
  const setToken = (newToken: string) => {
    token.value = newToken
    // 存一份到Cookie中
    setLocationToken(newToken)
  }

  // 清除 Token
  const removeToken = () => {
    token.value = ""
    removeLocationToken
  }
  return {
    token,
    setToken,
    removeToken,
  }
})
